/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 11.11.2003 by RST.
// $Id: mmove_t.java,v 1.2 2004/08/20 21:29:57 salomo Exp $
using System;
using Lib = Suake2.UI.util.Lib;
using QuakeFile = Suake2.UI.util.QuakeFile;
namespace Suake2.UI.game
{
	
	public class mmove_t
	{
		public mmove_t(int firstframe, int lastframe, mframe_t[] frame, EntThinkAdapter endfunc)
		{
			
			this.firstframe = firstframe;
			this.lastframe = lastframe;
			this.frame = frame;
			this.endfunc = endfunc;
		}
		
		public mmove_t()
		{
		}
		
		public int firstframe;
		public int lastframe;
		public mframe_t[] frame; //ptr
		public EntThinkAdapter endfunc;
		
		
		/// <summary>Writes the structure to a random acccess file. </summary>
		public virtual void  write(QuakeFile f)
		{
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) firstframe);
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int32) lastframe);
			if (frame == null)
			{
				System.IO.BinaryWriter temp_BinaryWriter3;
				temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter3.Write((System.Int32) (- 1));
			}
			else
			{
				System.IO.BinaryWriter temp_BinaryWriter4;
				temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter4.Write((System.Int32) frame.Length);
				for (int n = 0; n < frame.Length; n++)
					frame[n].write(f);
			}
			f.writeAdapter(endfunc);
		}
		
		/// <summary>Read the mmove_t from the RandomAccessFile. </summary>
		public virtual void  read(QuakeFile f)
		{
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			firstframe = temp_BinaryReader.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			lastframe = temp_BinaryReader2.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			int len = temp_BinaryReader3.ReadInt32();
			
			frame = new mframe_t[len];
			for (int n = 0; n < len; n++)
			{
				frame[n] = new mframe_t();
				frame[n].read(f);
			}
			endfunc = (EntThinkAdapter) f.readAdapter();
		}
	}
}